package cn.south.campus.admin.campus.controller;

import cn.south.campus.admin.campus.model.req.AdPositionReq;
import cn.south.campus.admin.campus.model.vo.AdPositionVO;
import cn.south.campus.admin.campus.service.AdPositionService;
import cn.south.campus.common.model.bo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 广告位表 前端控制器
 * </p>
 *
 * @author chow
 * @since 2024-11-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/campus/adPos")
public class AdPositionController {

    private final AdPositionService adPositionService;

    @GetMapping("/list")
    public Result<List<AdPositionVO>> list(AdPositionReq req) {
        return Result.success(adPositionService.listPos(req));
    }

    @GetMapping("page")
    public Result<IPage<AdPositionVO>> page(AdPositionReq req) {
        return Result.success(adPositionService.pagePos(req));
    }

    @GetMapping("/detail/{id}")
    public Result<AdPositionVO> detail(@PathVariable Long id) {
        return Result.success(AdPositionVO.convert(adPositionService.getById(id)));
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody AdPositionVO adPositionVO) {
        adPositionService.savePos(adPositionVO);
        return Result.success("添加成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody AdPositionVO adPositionVO) {
        adPositionService.updatePos(adPositionVO);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result<String> delete(@PathVariable Long id) {
        adPositionService.removeById(id);
        return Result.success("删除成功");
    }
}
